/*
* @Author: Administrator
* @Date:   2017-09-04 15:20:38
* @Last Modified by:   Administrator
* @Last Modified time: 2018-01-03 13:05:51
*/
const path = require('path');
const webpack = require('webpack'); 
const ROOT_PATH = path.resolve(__dirname); 
const ExtractTextPlugin=require('extract-text-webpack-plugin');
const HtmlWebpackPlugin=require('html-webpack-plugin');
const config={
	devtool:false,
	entry:{
		index:['./src/index.jsx'],
		admin:['./src/admin.jsx'],
	},
	output:{
		path 		: __dirname+'/dist/',
		publicPath 	: '/dist/',
		filename 	: 'js/[name].[chunkhash:8].js',
	},
  resolve: {
    extensions: ['.js', '.jsx']
  },
	module:{
		rules:[
      // {
      //   enforce:"pre",
      //   test:/\.(js|jsx)$/,
      //   loader:"eslint-loader",
      //   exclude:"/node_modules/"
      // },
			{test:/\.jsx$/,loader:'babel-loader',exclude:'/node_modules/' },
			{test:/\.js$/,loader:'babel-loader',exclude:'/node_modules/' },
      {test: /\.(gif|jpg|png|woff|svg|eot|ttf)\??.*$/, loader: 'url-loader?limit=20000&name=resource/[name].[ext]'},
			{test:/\.css$/,
        loader:ExtractTextPlugin.extract({
          fallback: "style-loader",
          use:[
              {
                  loader: 'css-loader',
                  options:{
                      minimize: true //css压缩
                  }
              }
          ]
			})}
		]
	},
	plugins:[
	 	new webpack.optimize.UglifyJsPlugin({
      compress: {
        //supresses warnings, usually from module minification
        warnings: false
      }
    }),
		new ExtractTextPlugin("css/[name].[contenthash:8].css"),
		new webpack.DefinePlugin({
		  "process.env":{
		    NODE_ENV:JSON.stringify('production')
		   }
		}),
    // 处理html
    new HtmlWebpackPlugin({
        filename        : 'index.html',
        title           : 'React News',
        template: path.join(__dirname, 'src/index.html'),
        inject          : true,
        hash            : false,
        chunks          : [,'index'],
        chunksSortMode  : 'dependency',
        minify          : {
            removeComments: true,
            collapseWhitespace: false
        }
    }),
    new HtmlWebpackPlugin({
      filename: 'index.ejs',
      template: '!!ejs-compiled-loader!' + path.join(__dirname, 'server/template.ejs'),
      inject: true,
      hash: true,
      chunks: ['index'],
      chunksSortMode: 'dependency',
      minify: {
        removeComments: true,
        collapseWhitespace: false
      }
    }),
 		new HtmlWebpackPlugin({
			filename: 'admin.html',
      template: path.join(__dirname, 'src/admin.html'),
			inject: true,
			hash: true,
			chunks: ['admin'],
			chunksSortMode: 'dependency',
			minify: {
				removeComments: true,
				collapseWhitespace: false
			}
		}),
    // dll插件
    new webpack.DllReferencePlugin({
        manifest: require(path.resolve(ROOT_PATH, 'dist/lib', 'manifest.json')),
        context: ROOT_PATH
    }),
	]
}
module.exports=config;
